package com.zj.joke.util;

import java.io.IOException;
import java.util.ArrayList;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.zj.joke.form.RemoteCategoryItem;

public class RemoteCategoryUtils {
	public static ArrayList<RemoteCategoryItem> getCategorys(String url) {
		ArrayList<RemoteCategoryItem> navigationItems = new ArrayList<RemoteCategoryItem>();
		try {
			Document document = null;
			document = Jsoup.connect(url).get();
			Elements categorys = document.select("div.classification-section")
					.select("a[href]");
			for (Element category : categorys) {
				RemoteCategoryItem item = new RemoteCategoryItem();
				item.setImage(null);
				item.setCategory(CategoryUtils.getCategoryCategory(category
						.text()));
				item.setCount(CategoryUtils.getCategoryCount(category.text()));
				item.setUrl(category.attr("abs:href"));
				navigationItems.add(item);
				// String name = category.text();
				// String urlString = category.attr("abs:href");

				// System.out.println(name);
				// System.out.println(urlString);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return navigationItems;
	}
}
